#pragma once

#include <QObject>
#include <QThread>
#include <QMutex>
#include <QWaitCondition>
#include <QTimer>
#include <QString>
#include <memory>

#include <AlgManager/CMeCamera.h>
#include <AlgManager/DataX.h>


class MeCameraWorker : public QObject
{
    Q_OBJECT

public:
    explicit MeCameraWorker(QObject* parent = nullptr);
    ~MeCameraWorker();

public slots:
    void initialize();
    void startAcquisition(int intervalMs = 1000);
    void stopAcquisition();
    void triggerSingleShot();
    void disconnectCamera();
    void connectCamera(const QString& ipAddress);

signals:
    void cameraOpened(bool success, const QString& message);
    void cameraClosed();
    void acquisitionStarted();
    void acquisitionStopped();
    void frameAcquired(const s_Image3dS& frame);
    void errorOccurred(const QString& errorMessage);
    void devicesEnumerated(const s_DevicesInfo& devicesInfo);
public:
    bool isCameraConnected();
    bool isAcquiring() const;

private slots:
    void acquisitionLoop();

private:
    CMeCamera m_camera;
    QTimer* m_acquisitionTimer;
    bool m_isAcquiring;
    int m_acquisitionInterval;
    QMutex m_mutex;
private:
    // 添加状态变量
    bool m_cameraConnected = false;
};
